<template>
  <el-dialog :title="title" :visible.sync="dialogVisible" :close-on-click-modal="false" width="700px">
    <div class="form-box">
      <el-form ref="form" :model="form" :inline="true" :rules="rules" label-width="auto" class="demo-ruleForm"
        v-loading="loading">
        <el-row>
          <el-form-item label="包赔商" prop="baopei">
            <el-select v-model="form.baopei" placeholder="请选择包赔商" size="small" filterable clearable
              @change="baopeiChange">
              <el-option v-for="dict in baopeishangList" :key="dict.userId" :label="dict.nickName" :value="dict.userId" />
            </el-select>
          </el-form-item>
          <div style="text-align: center;">
            <el-button type="primary" @click="submitForm('form')" v-loading="loading">确认</el-button>
          </div>
        </el-row>
      </el-form>
    </div>
  </el-dialog>
</template>

<script>
import onSelfApi from '@/api/retrieveManage/onSelf.js'
import { getSupplyList } from "@/api/info/info";
export default {
  name: "",
  data() {
    return {
      dialogVisible: false,
      loading: false,
      title: "选择包赔商",
      baopeishangList: [],
      // 表单参数
      form: {
        baopei: '',
        name:''
      },
      queryParams: {
        pageNum: 1,
        pageSize: 999
      },
      rules: {
        baopei: [
          { required: true, message: "请选择包赔商", trigger: "blur" }
        ]
      }
    };
  },
  created() {
  },
  methods: {
    // 打开弹窗
    open(flag, data) {
      this.dialogVisible = true;
      this.form.baopei = ''
      this.form.name = ''
      this.loading = true;
      getSupplyList('baopeishang').then(response => {
        this.baopeishangList = response.data;
        this.loading = false;
      });
    },
    baopeiChange(e){
      this.baopeishangList.forEach(r=>{
        if(r.userId==e){
          this.form.name = r.nickName
        }
      })
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$confirm(`确定拉包赔商【${this.form.name}】进群吗?`, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then((r) => {
            this.$emit('pullBaopeiSure',this.form.baopei)
            this.dialogVisible = false
          })
        } else {
          //console.log('error submit!!');
          return false;
        }
      });

    },
    close() {
      this.dialogVisible = false;
    }
  }
};
</script>
<style scoped lang="css"></style>
